/*
// Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
*/

class code3 {
    //N 叉树的层序遍历
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> ret = new ArrayList<>();

        if(root == null) return ret;

        Queue<Node> q = new LinkedList<>();
        q.add(root);

        while(!q.isEmpty()) {
            int sz = q.size();
            List<Integer> list = new ArrayList<>();
            for(int i=0;i<sz;i++) {
                Node node = q.poll();
                list.add(node.val);
                List<Node> child = node.children;
                for(Node t : child) {
                    q.offer(t);
                }
            }
            ret.add(list);
        }
        return ret;
    }
}